package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yunhe.dao.BoardDao;
import cn.yunhe.dao.ReplyDao;
import cn.yunhe.dao.TopicDao;
import cn.yunhe.dao.impl.BoardDaoImpl;
import cn.yunhe.dao.impl.ReplyDaoImpl;
import cn.yunhe.dao.impl.TopicDaoImpl;
import cn.yunhe.entity.Board;
import cn.yunhe.entity.Reply;
import cn.yunhe.entity.Topic;

/**
 * Servlet implementation class TopicDetailServlet
 */
@WebServlet("/TopicDetailServlet")
public class TopicDetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TopicDetailServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		TopicDao topicDao = new TopicDaoImpl();	
		ReplyDao replydao=new ReplyDaoImpl();
		//BoardDao boardDao=new  BoardDaoImpl();
		List<Reply> reply=null;
		String tidStr = request.getParameter("tid");
		//String bidStr=request.getParameter("bid");
		int tid = -1;
		//int bid=-1;
		if(tidStr != null && !tidStr.trim().equals("")){
			tid = Integer.parseInt(tidStr);
		
		}
		//if(bidStr!=null && bidStr.trim().equals("")){
			//bid= Integer.parseInt(bidStr);
		//}
		Topic topic = topicDao.getTopicByTid(tid);
		reply	=  replydao.findReplyByTopicId(tid);
		//Board board  =  boardDao.getBoardById(bid);
		request.setAttribute("reply", reply);
		request.setAttribute("topic", topic);
		//request.setAttribute("board",board );
		request.getRequestDispatcher("topicDetail.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
